from django.shortcuts import render
from django.http import HttpResponse,HttpResponseRedirect
from app.luca_admin.models import Setting
from django.contrib import messages
from django.utils.translation import ugettext as _

def setting(request):
    setting_list = Setting.objects.all()
    context = {'setting_list': setting_list}
    return render(request, 'admin_setting.html',context)

def save(request):
    if request.POST:
        user = request.POST.get('user')
        password = request.POST.get('password')
        service_type = request.POST.get('service_type')
        sender_name = request.POST.get('sender_name')
               
        setting = Setting.objects.get(name="user")
        setting.setting=user
        setting.save() 

        setting = Setting.objects.get(name="password")
        setting.setting=password
        setting.save() 
        
        setting = Setting.objects.get(name="service_type")
        setting.setting=service_type
        setting.save() 
        
        setting = Setting.objects.get(name="sender_name")
        setting.setting=sender_name
        setting.save() 

        messages.add_message(request, messages.SUCCESS,  _("Success"))   
        
        
    return HttpResponseRedirect('/admin/setting/')  